<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="/include/commonHeader::commonHeader('随机人员列表')"></head>
<body class="gray-bg layer-blue">
<div class="wrapper wrapper-content  animated fadeInRight full-container">
    <div class="row">
        <div class="ibox float-e-margins">
            <div class="ibox-content">
                <div class="btn-group table-tool" id="exampleToolbar" role="group">
                    <input type="text" placeholder="请选择日期" style="width:120px;"
                           class="table-tool-btn pull-left text-center" id="flightDate"/>
                    <input id="query_param" type="text" class="table-tool-btn  pull-left"
                           placeholder="姓名"/>
                    <button type="button" class="btn btn-outline btn-success btn-refresh" data-toggle="tooltip"
                            title="查询" id="btn-search">
                        <i class="fa fa-search" aria-hidden="true"></i>
                    </button>
                    <!--<shiro:hasPermission1 name="crewdispatch:additionalCrew:add">-->
                        <button type="button" onclick="add()" class="btn btn-outline btn-success btn-refresh"
                                data-toggle="tooltip" title="添加">
                            <i class="fa fa-plus" aria-hidden="true"></i>
                        </button>
                    <!--</shiro:hasPermission1>-->
                    <button type="button" onclick="reload()" class="btn btn-outline btn-success btn-refresh"
                            data-toggle="tooltip" title="刷新">
                        <i class="fa fa-refresh" aria-hidden="true"></i>
                    </button>
                </div>
                <table id="exampleTable" data-classes="table table-hover table-condensed">
                    <thead>
                    <tr>
                    </tr>
                    </thead>
                </table>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    var p_delete = 'hidden';
    var p_edit = 'hidden';
</script>
<!--<shiro:hasPermission1 name="crewdispatch:additionalCrew:delete">-->
    <script type="text/javascript">
        p_delete = '';
    </script>
<!--</shiro:hasPermission1>
<shiro:hasPermission1 name="crewdispatch:additionalCrew:edit">-->
    <script type="text/javascript">
        p_edit = '';
    </script>
<!--</shiro:hasPermission1>-->

<script src="/plugins/bootstrapValidator/js/bootstrapValidator.min.js"></script>
<script src="/plugins/bootstrapValidator/js/language/zh_CN.js"></script>
<script src="/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.js"></script>
<script src="/plugins/bootstrap-datetimepicker/bootstrap-datetimepicker.zh-CN.js"></script>

<!-- 自定义js -->
<script th:inline="javascript">
    var prefix = "/additionalCrew";
    var moduleFlag = [[${moduleFlag}]];
    $(function () {
        $("#flightDate").datetimepicker({
            minView: "month",
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose: true,
            todayBtn: true,
            bootcssVer:3,
            todayHighlight: true,
            pickerPosition: "bottom-right"
        });
        $("#btn-search").click(function(){
            $("#exampleTable").bootstrapTable('refresh');
        });
        load();
    });

    function load() {
        $('#exampleTable').bootstrapTable(
            {
                method: 'post',
                url: prefix + "/list.do",
                iconSize: 'outline',
                striped: true,
                dataType: "json",
                pagination: true,
                clickToSelect: true,
                pageSize: 10,
                pageNumber: 1,
                showColumns: false,
                sidePagination: "server",
                contentType: "application/x-www-form-urlencoded",
                queryParams: function (params) {
                    return {
                        flightDate:  $("#flightDate").val(),
                        cName:$("#query_param").val(),
                        limit: params.limit,
                        offset: params.offset
                    };
                },
                onDblClickRow: function (row, $element, field) {
                    view(row.id);
                },
                columns: [
                    {
                        field: 'id',
                        title: '序号',
                        formatter: orderFormatter,
                        valign: 'middle',
                        align: 'center',
                        width: '40'
                    },
                    {
                        field: 'flightDate',
                        title: '航班日期'
                    },
                    {
                        field: 'flightNo',
                        title: '航班号'
                    },
                    {
                        field: 'flightVoyage',
                        title: '航程'
                    },
                    {
                        field: '_departureAirport',
                        title: '起飞站'
                    },
                    {
                        field: 'std',
                        title: '出发时间'
                    },
                    {
                        field: '_arrivalAirport',
                        title: '到达站'
                    },
                    {
                        field: 'sta',
                        title: '到达时间'
                    },
                    {
                        field: 'cName',
                        title: '姓名'
                    },
                    {
                        field: 'moduleFlag',
                        title: '人员类型'
                    },
                    {
                        field: 'sType',
                        title: '随机原因'
                    },
                    {
                        field: 'stats',
                        title: '是否控座'
                    },
                    {
                        field: 'payYn',
                        title: '是否计费'
                    },
                    {
                        title: '操作',
                        align: 'center',
                        visible: isShowOperation(),
                        width:'80',
                        formatter: function (value, row, index) {
                            return [
                                '<a class="' + p_edit + '" href="#" title="编辑" onclick="edit(' + row.id + ')">',
                                '<i class="glyphicon glyphicon-edit"></i>',
                                '</a>&nbsp;&nbsp;',
                                '<a class="' + p_delete + '" href="#" title="删除" onclick="remove(' + row.id + ')">',
                                '<i class="glyphicon glyphicon-remove text-danger"></i>',
                                '</a>&nbsp;&nbsp;'
                            ].join('');
                        }
                    }]
            })
    }

    //是否有权限显示 '操作' 列
    function isShowOperation() {
        return (p_edit != 'hidden' || p_delete != 'hidden');
    }

    //刷新
    function reload() {
        $("#query_param").val("");
        $("#flightDate").val("");
        $("#exampleTable").bootstrapTable('refresh');
    }

    //增加
    function add() {
        layer.open({
            type: 2,
            title: '新增',
            shadeClose: false, // 点击遮罩关闭层
            area: ['800px', '520px'],
            content: prefix + '/add.do?moduleFlag='+moduleFlag
        });
    }

    //编辑
    function edit(id) {
        layer.open({
            type: 2,
            title: '编辑',
            shadeClose: false, // 点击遮罩关闭层
            area: ['800px', '520px'],
            content: prefix + '/edit.do?id=' + id
        });
    }

    //查看
    function view(id) {
        layer.open({
            type: 2,
            title: '查看',
            shadeClose: false, // 点击遮罩关闭层
            area: ['800px', '520px'],
            content: prefix + '/view.do?id=' + id
        });
    }

    //删除
    function remove(id) {
        layer.confirm('确定要删除选中的记录？', {
            btn: ['确定', '取消']
        }, function (index) {
            $.ajax({
                url: prefix + "/delete.do",
                type: "post",
                data: {
                    'id': id
                },
                success: function (r) {
                    layer.close(index);
                    if (r.code == 0) {
                        toastr.success(r.msg);
                        reload();
                    } else {
                        toastr.warning(r.msg);
                    }
                },
                error:function(){
                    toastr.error('数据出错！');
                    layer.close(index);
                }
            });
        })
    }

</script>
</body>
</html>